﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleTest_1
{
    class Test : IComparable<Test>
    {
        // property
        public int m_nUin=0;
        public int Uin
        {
            get
            { 
                return m_nUin;
            }
            set 
            { 
                m_nUin=value;
            } 
        }

        public int CompareTo(Test test)
        {
            // 1 大于  0 等于 -1 小于 
            if (m_nUin > test.m_nUin)
            {
                return 1;
            }
            else if (m_nUin == test.m_nUin)
            {
                return 0;
            }
            else
            {
                return -1;
            }
        }

        public void SetUinData(int nUin)
        {
            m_nUin = nUin;
        }

        public void printStr(string str)
        {
            Console.WriteLine("Test printStr" + str);
        }

        public void printLog(string str)
        {
            Console.WriteLine("Test printLog" + str);
        }
    }

    class TestUtils
    {
        //delegate
        public delegate void GetStrTimeEnd(string str);
        public GetStrTimeEnd DeleGetTimeEnd=null;

        public event GetStrTimeEnd EventGetTime=null;
        static int m_nTest=0;
        // int to string
        public string IntToStr(int nIndex)
        {
            return nIndex.ToString();
        }
        // string to int
        public int StrToInt(string str)
        {
            return int.Parse(str);

            // or 
            int nResult;
            int.TryParse(str, out nResult);
            return Convert.ToInt32(str);
        }

        // time string
        public string GetCurrentTimeStr()
        {
            if (DeleGetTimeEnd!=null)
                DeleGetTimeEnd.Invoke(DateTime.Now.ToString());

            if (EventGetTime!=null)
                EventGetTime(DateTime.Now.ToString());

            return DateTime.Now.ToString();
        }
        // time stamp
        public long GetTimeStamp(DateTime time)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
            return (time.Ticks - startTime.Ticks) / 10000;
        }
        // loop and sort
        public void SortIntList(List<int> lRes)
        {
            int nSum=0;
            foreach (int nValue in lRes)
            {
                nSum += nValue;
            }

            lRes.Sort(); // 默认升序排列
            lRes.Sort((x, y) => -x.CompareTo(y)); // 降序排列
        }
        //
        public string GetTestListStr(List<Test> listTest)
        {
            string listStr ="";
            foreach (Test test in listTest)
            {
                listStr = string.Concat(listStr ,test.m_nUin.ToString());
            }
            return listStr;
        }
    }
}
